﻿@using ZBJF.Warranty.Common.Enums.InsuranceProducts
@using ZBJF.Warranty.Model
@model ZBJF.Warranty.Model.InsuranceProductOrder
@{
    ViewBag.Title = "在线支付";
    var tspan = (DateTime.Now - Model.CreateOrderTime).Minutes;
    var finalPayTime = Model.CreateOrderTime.AddMinutes(15);//最后付款时间，下单后15分钟内完成付款
}
<div class="desc_forward_title" onclick="history.back(-1)">
    在线支付
</div>
@using (Html.BeginForm("CreateInsuranceOrder", "InsuranceOrder", FormMethod.Post, new { id = "orderPayPage" }))
{
    @Html.AntiForgeryToken()
    @Html.HiddenFor(m => m.ID)
    <div class="weui-cells_form">
        <div class="pay_timeout_tip">
            <img src="~/Images/time_tip.png" />请于15分钟内完成支付！
        </div>
        <div class="timer_out">
            订单号:@Html.DisplayFor(o => o.OrderNo, new { @class = "weui-label" })
            @if (Model.Status == (byte)InsuranceProductOrderStatus.PendingPayment && tspan < 15)
            {

                <div class="time_out">
                    <img src="~/Images/time_out.png" />支付剩余时间<label id="timer">@(DateTime.Now - Model.CreateOrderTime)</label>
                </div>
            }
            else
            {
                <div class="time_out">
                    <img src="~/Images/time_out.png" /><label class="red">@ZBJF.Warranty.Common.Common.EnumHelper.Instance.GetDescription(typeof(InsuranceProductOrderStatus), Model.Status)</label>
                </div>
            }
        </div>
    </div>
    <div class="space-2"></div>
    <div class="order_pay_info">
        <div>
            @Html.DisplayFor(o => o.InsuranceProductName, new { @class = "weui-label" })×<label class="">@Model.BuyCount</label>
            <label class="float-right">@Model.SaleRetailPrice</label>
        </div>
        <div>
            合计金额<label class="float-right red">@Model.TotalPirce.ToString("c")</label>
        </div>
    </div>

    if (Model.Status == (byte)InsuranceProductOrderStatus.PendingPayment)
    {
        <div class="align-right padding-10 margin-t-10">
            <a class="weui-form-preview__btn weui-form-preview__btn_primary border-radius-6 @(tspan < 15 ? "" : "disable")" id="buybtn" href="@Url.Action("JsApiPayPage", "WeiXinPay", new { OrderId = Model.OrderNo, successUrl = "/InsuranceProductOrder/PaySuccess/" + Model.ID, cancelUrl = Request.Url.AbsoluteUri })" onclick="orderPayPage.submit()">确认支付 @Model.TotalPirce.ToString("c")</a>
        </div>
        <div class="align-right padding-10">
            <a class="weui-form-preview__btn weui-form-preview__btn_primary border-radius-6 bg-gray @(tspan < 15 ? "" : "disable")" id="btnCancel" href="javascript:void(0)" onclick="if (confirm('确定要取消吗？')) {orderPayPage.submit();} else {return false;}">取消订单</a>
        </div>
    }

}
<script>
    $(function() {
        try {
            parent.layer.close();
        } catch (e) {

        } 
        var timer= document.getElementById("timer");
        if (timer) {
            leftTimer(@finalPayTime.Year,@finalPayTime.Month,@finalPayTime.Day,@finalPayTime.Hour,@finalPayTime.Minute,@finalPayTime.Second);
        }
    });
    function leftTimer(year, month, day, hour, minute, second) {
        var leftTime = (new Date(year, month - 1, day, hour, minute, second)) - (new Date()); //计算剩余的毫秒数
        var minutes = parseInt(leftTime / 1000 / 60 % 60, 10);//计算剩余的分钟
        var seconds = parseInt(leftTime / 1000 % 60, 10);//计算剩余的秒数
        minutes = checkTime(minutes);
        seconds = checkTime(seconds);
        var interval= setInterval("leftTimer(@finalPayTime.Year,@finalPayTime.Month,@finalPayTime.Day,@finalPayTime.Hour,@finalPayTime.Minute,@finalPayTime.Second)", 1000);
        if (seconds > 0) {
            document.getElementById("timer").innerHTML = minutes + ":" + seconds;
        } else {
            document.getElementById("timer").innerHTML = "已超时取消";
            clearInterval(interval);
        }
    }
    function checkTime(i) { //将0-9的数字前面加上0，例1变为01
        if (i < 10&&i>0) {
            i = "0" + i;
        }
        return i;
    }

</script>
